package idv.loveloser.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.Transaction;
import org.hibernate.criterion.Example;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * A data access object (DAO) providing persistence and search support for
 * MdlAssignmentSubmissions entities. Transaction control of the save(),
 * update() and delete() operations can directly support Spring
 * container-managed transactions or they can be augmented to handle
 * user-managed Spring transactions. Each of these methods provides additional
 * information for how to configure it for the desired type of transaction
 * control.
 * 
 * @see idv.loveloser.dao.MdlAssignmentSubmissions
 * @author MyEclipse Persistence Tools
 */

public class MdlAssignmentSubmissionsDAO extends BaseHibernateDAO {
	private static final Logger log = LoggerFactory
			.getLogger(MdlAssignmentSubmissionsDAO.class);
	// property constants
	public static final String ASSIGNMENT = "assignment";
	public static final String USERID = "userid";
	public static final String TIMECREATED = "timecreated";
	public static final String TIMEMODIFIED = "timemodified";
	public static final String NUMFILES = "numfiles";
	public static final String DATA1 = "data1";
	public static final String DATA2 = "data2";
	public static final String GRADE = "grade";
	public static final String SUBMISSIONCOMMENT = "submissioncomment";
	public static final String FORMAT = "format";
	public static final String TEACHER = "teacher";
	public static final String TIMEMARKED = "timemarked";
	public static final String MAILED = "mailed";

	public void save(MdlAssignmentSubmissions transientInstance) {
		Transaction trx = getSession().beginTransaction();
		log.debug("saving MdlAssignmentSubmissions instance");
		try {
			getSession().save(transientInstance);
			trx.commit();
			log.debug("save successful");
			trx=null;
		} catch (RuntimeException re) {
			log.error("save failed", re);
			trx=null;
			throw re;
		}
	}

	public void delete(MdlAssignmentSubmissions persistentInstance) {
		log.debug("deleting MdlAssignmentSubmissions instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public MdlAssignmentSubmissions findById(java.lang.Long id) {
		log.debug("getting MdlAssignmentSubmissions instance with id: " + id);
		try {
			MdlAssignmentSubmissions instance = (MdlAssignmentSubmissions) getSession()
					.get("idv.loveloser.dao.MdlAssignmentSubmissions", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(MdlAssignmentSubmissions instance) {
		log.debug("finding MdlAssignmentSubmissions instance by example");
		try {
			List results = getSession()
					.createCriteria(
							"idv.loveloser.dao.MdlAssignmentSubmissions")
					.add(Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding MdlAssignmentSubmissions instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from MdlAssignmentSubmissions as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByAssignment(Object assignment) {
		return findByProperty(ASSIGNMENT, assignment);
	}

	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	public List findByTimecreated(Object timecreated) {
		return findByProperty(TIMECREATED, timecreated);
	}

	public List findByTimemodified(Object timemodified) {
		return findByProperty(TIMEMODIFIED, timemodified);
	}

	public List findByNumfiles(Object numfiles) {
		return findByProperty(NUMFILES, numfiles);
	}

	public List findByData1(Object data1) {
		return findByProperty(DATA1, data1);
	}

	public List findByData2(Object data2) {
		return findByProperty(DATA2, data2);
	}

	public List findByGrade(Object grade) {
		return findByProperty(GRADE, grade);
	}

	public List findBySubmissioncomment(Object submissioncomment) {
		return findByProperty(SUBMISSIONCOMMENT, submissioncomment);
	}

	public List findByFormat(Object format) {
		return findByProperty(FORMAT, format);
	}

	public List findByTeacher(Object teacher) {
		return findByProperty(TEACHER, teacher);
	}

	public List findByTimemarked(Object timemarked) {
		return findByProperty(TIMEMARKED, timemarked);
	}

	public List findByMailed(Object mailed) {
		return findByProperty(MAILED, mailed);
	}

	public List findAll() {
		log.debug("finding all MdlAssignmentSubmissions instances");
		try {
			String queryString = "from MdlAssignmentSubmissions";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public MdlAssignmentSubmissions merge(
			MdlAssignmentSubmissions detachedInstance) {
		Transaction trx =getSession().beginTransaction();
		log.debug("merging MdlAssignmentSubmissions instance");
		try {
			MdlAssignmentSubmissions result = (MdlAssignmentSubmissions) getSession()
					.merge(detachedInstance);
			trx.commit();
			log.debug("merge successful");
			trx=null;
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			trx=null;
			throw re;
		}
	}

	public void attachDirty(MdlAssignmentSubmissions instance) {
		log.debug("attaching dirty MdlAssignmentSubmissions instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(MdlAssignmentSubmissions instance) {
		log.debug("attaching clean MdlAssignmentSubmissions instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}